/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import Base.Dados;
import Base.ExtensionFileFilter;
import Base.ImageTest;
import Base.Tema;
import Controle.ControlePergunta;
import Controle.ControleTema;
import DAO.DaoPergunta;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Guilherme
 */
public class Adm extends javax.swing.JFrame {

    /**
     * Creates new form Adm
     */
    /*
     * @author Rosana
     *
     */
    public Adm() {

        dt = new ControleTema();

        icon = new ImageIcon("");
        fc = new JFileChooser();
        filter = new ExtensionFileFilter();
        filter.addExtension("jpg");
        filter.addExtension("jpeg");
        filter.addExtension("gif");
        filter.addExtension("png");
        filter.addExtension("bitmap");
        filter.setDescription("Image files");

        fc.setFileFilter(filter);
        initComponents();
        cp = new ControlePergunta();

        DaoPergunta dp = new DaoPergunta();
        dados = null;

        preencherComboBox();
    }

    public void preencherComboBox() {
        lista = dt.getTemas();
        for (int i = 0; i < lista.length; i++) {
            comboTema.addItem(lista[i]);
        }
    }

    public void setDados(Dados dados) {
        this.dados = dados;
    }

    public void preencher() {

        for (int i = 0; i < lista.length; i++) {
            if (lista[i].getId() == dados.getTema().getId()) {
                comboTema.setSelectedIndex(i);
            }
        }

        rdNao.setSelected(true);
        rdSim.setSelected(false);
        comboTema.setEnabled(true);
        txtAreaQuestao1.setText(dados.getPergunta().getPergunta());
        txtAreaOptA.setText(dados.getResp1().getDescricao());
        txtAreaOptB.setText(dados.getResp2().getDescricao());
        txtAreaOptC.setText(dados.getResp3().getDescricao());
        txtAreaOptD.setText(dados.getResp4().getDescricao());
        if (dados.getResp1().isCorreta()) {
            txtAlternativa.setText("A");
        } else if (dados.getResp2().isCorreta()) {
            txtAlternativa.setText("B");
        } else if (dados.getResp3().isCorreta()) {
            txtAlternativa.setText("C");
        } else {
            txtAlternativa.setText("D");
        }
        txtAreaComentario.setText(dados.getPergunta().getComentario());
        txtLink.setText(dados.getPergunta().getLink());
        if (dados.getPergunta().getImagem() != null) {
            ImageTest.writeByteArrayToFile(dados.getPergunta().getImagem());
            caminho = ".\\src\\Imagens\\busca.png";
            addImagem();
            btnAddImagem.setText("Remover Imagem");
            btnAddImagem.setFont(new java.awt.Font("Tahoma", Font.BOLD, 12));
            btnAddImagem.repaint();
        }
    }

    private void addImagem() {
        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
        BufferedImage original = null;
        try {
            original = ImageIO.read(new File(caminho));
        } catch (IOException ex) {
            Logger.getLogger(Adm.class.getName()).log(Level.SEVERE, null, ex);
        }

        int origW = 0;
        int origH = 0;
        float fator = 0;

        if (original.getWidth() >= original.getHeight()) {
            fator = (float) (label.getWidth()) / (float) (original.getWidth());
        } else {
            fator = ((float) label.getHeight() - 5) / ((float) original.getHeight() - 5);
        }


        origW = (int) (original.getWidth() * fator);
        origH = (int) (original.getHeight() * fator);

        if (origW > label.getWidth()) {
            origW = label.getWidth();
        }
        if (origH > label.getHeight()) {
            origH = label.getHeight();
        }

        if (original.getWidth() <= label.getWidth() && original.getHeight() <= label.getHeight()) {
            origW = original.getWidth();
            origH = original.getHeight();
        }

        ImageTest.exec(caminho, origW - 20, origH - 20);

        try {
            icon.setImage(ImageIO.read(new File(".\\src\\Imagens\\result.png")));
        } catch (IOException ex) {
            Logger.getLogger(Adm.class.getName()).log(Level.SEVERE, null, ex);
        }
        label.repaint();
        label.setIcon(icon);
        label.repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        lblTema = new javax.swing.JLabel();
        rdSim = new javax.swing.JRadioButton();
        rdNao = new javax.swing.JRadioButton();
        txtTema = new javax.swing.JTextField();
        comboTema = new javax.swing.JComboBox();
        lblQuestao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAreaComentario = new javax.swing.JTextArea();
        lblOptA = new javax.swing.JLabel();
        lblOptB = new javax.swing.JLabel();
        lblOptC = new javax.swing.JLabel();
        lblOptD = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAreaOptA = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtAreaOptB = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtAreaOptC = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        txtAreaOptD = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        txtAreaQuestao1 = new javax.swing.JTextArea();
        lblComentario = new javax.swing.JLabel();
        lblLink = new javax.swing.JLabel();
        txtLink = new javax.swing.JTextField();
        btnSalvar = new javax.swing.JButton();
        btnAddImagem = new javax.swing.JButton();
        lblIconeAdm = new javax.swing.JLabel();
        lblTitulo = new javax.swing.JLabel();
        label = new javax.swing.JLabel();
        txtAlternativa = new javax.swing.JFormattedTextField();
        btnVoltar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Quiz Responda e Aprenda - Administrativo");
        setExtendedState(1);
        setResizable(false);
        getContentPane().setLayout(null);

        lblTema.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTema.setText("Novo Tema ?");
        getContentPane().add(lblTema);
        lblTema.setBounds(24, 35, 75, 44);

        rdSim.setSelected(true);
        rdSim.setText("Sim");
        rdSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdSimActionPerformed(evt);
            }
        });
        getContentPane().add(rdSim);
        rdSim.setBounds(134, 35, 41, 23);

        rdNao.setText("Não");
        rdNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdNaoActionPerformed(evt);
            }
        });
        getContentPane().add(rdNao);
        rdNao.setBounds(134, 61, 45, 23);
        getContentPane().add(txtTema);
        txtTema.setBounds(197, 36, 232, 20);

        comboTema.setModel(new javax.swing.DefaultComboBoxModel());
        comboTema.setEnabled(false);
        getContentPane().add(comboTema);
        comboTema.setBounds(197, 62, 232, 20);

        lblQuestao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblQuestao.setText("Questão: ");
        getContentPane().add(lblQuestao);
        lblQuestao.setBounds(24, 117, 75, 15);

        txtAreaComentario.setColumns(20);
        txtAreaComentario.setLineWrap(true);
        txtAreaComentario.setRows(5);
        jScrollPane1.setViewportView(txtAreaComentario);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(474, 143, 408, 80);

        lblOptA.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblOptA.setText("A: ");
        getContentPane().add(lblOptA);
        lblOptA.setBounds(24, 241, 16, 15);

        lblOptB.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblOptB.setText("B: ");
        getContentPane().add(lblOptB);
        lblOptB.setBounds(24, 295, 15, 15);

        lblOptC.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblOptC.setText("C: ");
        getContentPane().add(lblOptC);
        lblOptC.setBounds(25, 351, 15, 15);

        lblOptD.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblOptD.setText("D: ");
        getContentPane().add(lblOptD);
        lblOptD.setBounds(24, 407, 16, 15);

        txtAreaOptA.setColumns(20);
        txtAreaOptA.setLineWrap(true);
        txtAreaOptA.setRows(5);
        jScrollPane2.setViewportView(txtAreaOptA);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(44, 241, 385, 45);

        txtAreaOptB.setColumns(20);
        txtAreaOptB.setLineWrap(true);
        txtAreaOptB.setRows(5);
        jScrollPane3.setViewportView(txtAreaOptB);

        getContentPane().add(jScrollPane3);
        jScrollPane3.setBounds(44, 295, 385, 45);

        txtAreaOptC.setColumns(20);
        txtAreaOptC.setLineWrap(true);
        txtAreaOptC.setRows(5);
        jScrollPane4.setViewportView(txtAreaOptC);

        getContentPane().add(jScrollPane4);
        jScrollPane4.setBounds(44, 351, 385, 45);

        txtAreaOptD.setColumns(20);
        txtAreaOptD.setRows(5);
        jScrollPane5.setViewportView(txtAreaOptD);

        getContentPane().add(jScrollPane5);
        jScrollPane5.setBounds(44, 407, 385, 45);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Resposta Correta: ");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(20, 470, 101, 15);

        txtAreaQuestao1.setColumns(20);
        txtAreaQuestao1.setLineWrap(true);
        txtAreaQuestao1.setRows(5);
        jScrollPane6.setViewportView(txtAreaQuestao1);

        getContentPane().add(jScrollPane6);
        jScrollPane6.setBounds(24, 143, 405, 80);

        lblComentario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblComentario.setText("Comentário Sobre a Questão: ");
        getContentPane().add(lblComentario);
        lblComentario.setBounds(474, 117, 408, 15);

        lblLink.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblLink.setText("Link Para Mais Informações: ");
        getContentPane().add(lblLink);
        lblLink.setBounds(474, 243, 153, 15);
        getContentPane().add(txtLink);
        txtLink.setBounds(631, 241, 251, 20);

        btnSalvar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/salvar2.png"))); // NOI18N
        btnSalvar.setText("Salvar");
        btnSalvar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnSalvar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSalvar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/salvar2.png"))); // NOI18N
        btnSalvar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSalvarMouseClicked(evt);
            }
        });
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalvar);
        btnSalvar.setBounds(507, 519, 160, 40);

        btnAddImagem.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnAddImagem.setText("Anexar Imagem");
        btnAddImagem.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnAddImagem.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAddImagem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddImagemActionPerformed(evt);
            }
        });
        getContentPane().add(btnAddImagem);
        btnAddImagem.setBounds(620, 460, 120, 30);

        lblIconeAdm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/addQuestao6.png"))); // NOI18N
        getContentPane().add(lblIconeAdm);
        lblIconeAdm.setBounds(734, 11, 113, 100);

        lblTitulo.setFont(new java.awt.Font("Andalus", 3, 24)); // NOI18N
        lblTitulo.setText("Cadastro de Questões");
        getContentPane().add(lblTitulo);
        lblTitulo.setBounds(466, 46, 250, 38);

        label.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        label.setBorder(javax.swing.BorderFactory.createTitledBorder("Imagem"));
        getContentPane().add(label);
        label.setBounds(466, 267, 416, 185);

        try {
            txtAlternativa.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("U")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtAlternativa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtAlternativaKeyReleased(evt);
            }
        });
        getContentPane().add(txtAlternativa);
        txtAlternativa.setBounds(130, 470, 26, 20);

        btnVoltar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btnVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/voltar.png"))); // NOI18N
        btnVoltar.setText("Voltar");
        btnVoltar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        btnVoltar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnVoltar.setPreferredSize(new java.awt.Dimension(107, 41));
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });
        getContentPane().add(btnVoltar);
        btnVoltar.setBounds(700, 520, 160, 40);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-936)/2, (screenSize.height-615)/2, 936, 615);
    }// </editor-fold>//GEN-END:initComponents

    private void rdSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdSimActionPerformed
        rdNao.setSelected(false);
        txtTema.setEnabled(true);
        comboTema.setEnabled(false);
    }//GEN-LAST:event_rdSimActionPerformed

    /*
     * @author Rosana
     *
     */
    private void btnAddImagemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddImagemActionPerformed


        if (btnAddImagem.getText().equals("Anexar Imagem")) {

            label.setText("");
            label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            label.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
            fc.setMultiSelectionEnabled(true);
            if ("".equals(caminho)) {
                fc.setCurrentDirectory(new File("C:\\tmp"));
            } else {
                fc.setCurrentDirectory(new File(caminho));
            }

            int option = fc.showOpenDialog(this);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (filter.accept(file)) {
                    caminho = file.getAbsolutePath();
                    BufferedImage original = null;
                    try {
                        original = ImageIO.read(new File(caminho));
                    } catch (IOException ex) {
                        Logger.getLogger(Adm.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    int origW = 0;
                    int origH = 0;
                    float fator = 0;
                    if (original.getWidth() >= original.getHeight()) {
                        fator = (float) (label.getWidth()) / (float) (original.getWidth());
                    } else {
                        fator = ((float) label.getHeight()) / ((float) original.getHeight());
                    }

                    origW = (int) (original.getWidth() * fator);
                    origH = (int) (original.getHeight() * fator);

                    if (origW > label.getWidth()) {
                        origW = label.getWidth();
                    }
                    if (origH > label.getHeight()) {
                        origH = label.getHeight();
                    }

                    if (original.getWidth() <= label.getWidth() && original.getHeight() <= label.getHeight()) {
                        origW = original.getWidth();
                        origH = original.getHeight();
                    }

                    ImageTest.exec(caminho, origW - 20, origH - 20);
                    try {
                        icon.setImage(ImageIO.read(new File(".\\src\\Imagens\\result.png")));
                    } catch (IOException ex) {
                        Logger.getLogger(Adm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    label.repaint();
                    label.setIcon(icon);
                    btnAddImagem.setText("Remover Imagem");
                    btnAddImagem.setFont(new java.awt.Font("Tahoma", Font.BOLD, 12));
                    btnAddImagem.repaint();
                } else {
                    try {
                        icon.setImage(ImageIO.read(new File(".\\src\\Imagens\\errado.png")));


                    } catch (IOException ex) {
                        Logger.getLogger(Adm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    label.setIcon(icon);
                }
            } else {
            }
        } else {
            caminho = "";
            label.setIcon(new ImageIcon());
            label.repaint();
            btnAddImagem.setText("Anexar Imagem");
            btnAddImagem.setFont(new java.awt.Font("Tahoma", Font.BOLD, 12));
            btnAddImagem.repaint();
        }


    }//GEN-LAST:event_btnAddImagemActionPerformed

    private void btnSalvarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSalvarMouseClicked
        System.out.println("Let the fight begins!!");

        if (rdSim.isSelected() == true && txtTema.getText().equalsIgnoreCase("")) {
            JOptionPane.showMessageDialog(rootPane, "É necessário cadastrar um novo tema \n ou selecionar uma das opções disponíveis!", "ERRO", JOptionPane.ERROR_MESSAGE);
        } else {
            if ((txtAreaQuestao1.getText().equalsIgnoreCase("")) || (txtAreaOptA.getText().equalsIgnoreCase(""))
                    || (txtAreaOptB.getText().equalsIgnoreCase("")) || (txtAreaOptC.getText().equalsIgnoreCase(""))
                    || (txtAreaOptD.getText().equalsIgnoreCase("")) || (txtAlternativa.getText().equalsIgnoreCase(""))
                    || (txtAreaComentario.getText().equalsIgnoreCase(""))) {
                JOptionPane.showMessageDialog(rootPane, "É Necessário preencher todos os campos!", "ERRO", JOptionPane.ERROR_MESSAGE);
            } else {
                if ((!txtAlternativa.getText().equalsIgnoreCase("a")) && (!txtAlternativa.getText().equalsIgnoreCase("b"))
                        && (!txtAlternativa.getText().equalsIgnoreCase("c")) && (!txtAlternativa.getText().equalsIgnoreCase("d"))) {
                    JOptionPane.showMessageDialog(rootPane, "O campo Resposta Correta apenas aceita os caracteres: A,B,C e D!", "ERRO", JOptionPane.ERROR_MESSAGE);
                } else {

                    if (dados == null) {
                        System.out.println("Codigo para salvar no banco de dados");

                        //Dados Tema
                        int tem;
                        String tema = null;
                        if (rdSim.isSelected()) {
                            tema = txtTema.getText();
                            tem = -1;
                        } else {
                            tem = ((Tema) comboTema.getSelectedItem()).getId();
                        }

                        //Dados Pergunta
                        String pergunta = txtAreaQuestao1.getText();
                        String coment = txtAreaComentario.getText();
                        String link = txtLink.getText();

                        //Dados Alternativa
                        String altA = txtAreaOptA.getText();
                        String altB = txtAreaOptB.getText();
                        String altC = txtAreaOptC.getText();
                        String altD = txtAreaOptD.getText();
                        String altCorreta = txtAlternativa.getText();


                        ControlePergunta idb = new ControlePergunta();

                        int soluc = idb.InsereDB(tema, tem, pergunta, coment, link, caminho, altA, altB, altC, altD, altCorreta);
                        if (soluc == 1) {
                            JOptionPane.showMessageDialog(rootPane, "Pergunta Inserida com Sucesso!", "SUCESSO", JOptionPane.INFORMATION_MESSAGE);
                            this.setVisible(false);
                            Adm adm = new Adm();
                            adm.setVisible(true);
                        } else if (soluc == 3) {
                            JOptionPane.showMessageDialog(rootPane, "Banco de dados indisponível!", "ERRO", JOptionPane.ERROR_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(rootPane, "Imagem não pode ser convertida!", "ERRO", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        int result;
                        //editar
                        if (rdSim.isSelected()) {
                            result = cp.update(dados, txtTema.getText(), null,
                                    txtAreaQuestao1.getText(), txtAreaComentario.getText(), txtLink.getText(),
                                    caminho, txtAreaOptA.getText(), txtAreaOptB.getText(),
                                    txtAreaOptC.getText(), txtAreaOptD.getText(), txtAlternativa.getText());
                        } else {

                            result = cp.update(dados, null, (Tema) comboTema.getSelectedItem(),
                                    txtAreaQuestao1.getText(), txtAreaComentario.getText(), txtLink.getText(),
                                    caminho, txtAreaOptA.getText(), txtAreaOptB.getText(),
                                    txtAreaOptC.getText(), txtAreaOptD.getText(), txtAlternativa.getText());
                        }

                        if (result == 1) {
                            JOptionPane.showMessageDialog(rootPane, "Pergunta Alterada com Sucesso!", "SUCESSO", JOptionPane.INFORMATION_MESSAGE);
                            dados = null;
                            this.setVisible(false);
                            Adm adm = new Adm();
                            adm.setVisible(true);
                        } else if (result == 3) {
                            JOptionPane.showMessageDialog(rootPane, "Banco de dados indisponível!", "ERRO", JOptionPane.ERROR_MESSAGE);
                        } else if (result == 5) {
                            JOptionPane.showMessageDialog(rootPane, "Ocorreu um erro inesperado! \nVerifique os dados e tente novamente!", "ERRO", JOptionPane.ERROR_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(rootPane, "Imagem não pode ser convertida!", "ERRO", JOptionPane.ERROR_MESSAGE);
                        }


                    }

                }

            }
        }
    }//GEN-LAST:event_btnSalvarMouseClicked

    private void rdNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdNaoActionPerformed
        rdSim.setSelected(false);
        txtTema.setEnabled(false);
        comboTema.setEnabled(true);
    }//GEN-LAST:event_rdNaoActionPerformed

    private void txtAlternativaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAlternativaKeyReleased
        if (!txtAlternativa.getText().equalsIgnoreCase("A") && !txtAlternativa.getText().equalsIgnoreCase("B")
                && !txtAlternativa.getText().equalsIgnoreCase("C") && !txtAlternativa.getText().equalsIgnoreCase("D")) {
            JOptionPane.showMessageDialog(rootPane, "Este campo só aceita os caracteres A, B, C e D", "ERRO", JOptionPane.ERROR_MESSAGE);
            txtAlternativa.setText("");
        }
    }//GEN-LAST:event_txtAlternativaKeyReleased

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        Relatorio rel = new Relatorio();
        rel.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_btnVoltarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnSalvarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Adm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Adm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Adm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Adm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Adm().setVisible(true);
            }
        });
    }
    private String caminho = "";
    private ImageIcon icon;
    private final JFileChooser fc;
    private final ExtensionFileFilter filter;
    private ControleTema dt;
    private Dados dados;
    private Tema lista[];
    private ControlePergunta cp;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddImagem;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnVoltar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JComboBox comboTema;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JLabel label;
    private javax.swing.JLabel lblComentario;
    private javax.swing.JLabel lblIconeAdm;
    private javax.swing.JLabel lblLink;
    private javax.swing.JLabel lblOptA;
    private javax.swing.JLabel lblOptB;
    private javax.swing.JLabel lblOptC;
    private javax.swing.JLabel lblOptD;
    private javax.swing.JLabel lblQuestao;
    private javax.swing.JLabel lblTema;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JRadioButton rdNao;
    private javax.swing.JRadioButton rdSim;
    private javax.swing.JFormattedTextField txtAlternativa;
    private javax.swing.JTextArea txtAreaComentario;
    private javax.swing.JTextArea txtAreaOptA;
    private javax.swing.JTextArea txtAreaOptB;
    private javax.swing.JTextArea txtAreaOptC;
    private javax.swing.JTextArea txtAreaOptD;
    private javax.swing.JTextArea txtAreaQuestao1;
    private javax.swing.JTextField txtLink;
    private javax.swing.JTextField txtTema;
    // End of variables declaration//GEN-END:variables
}
